﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LCA.Community.DAL.Model;
using LCA.Community.DAL.Interfaces;

namespace LCA.Community.DAL
{
    /// <summary>
    /// The repository for questions data manipulation.
    /// </summary>
    public class QuestionsRepository : BaseRepository<Question>, IQuestionsRepository
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="QuestionsRepository"/> class.
        /// </summary>
        /// <param name="dataServiceContext">The data service context.</param>
        public QuestionsRepository(IDataServiceContext<Question> dataServiceContext)
            :base(dataServiceContext)
        {

        }

        /// <summary>
        /// Gets the questions page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="pageSize">Size of the page.</param>
        /// <returns>Questions page</returns>
        public List<Question> GetQuestionsPage(int page, int pageSize)
        {
            var questions = Entities.OrderByDescending(q => q.Timestamp).SkipWhile((q, i) => i < page * pageSize).Take(pageSize).ToList();
            return questions;
        }
    }
}
